﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Common.Base.Test;

namespace ExampleProject
{
    public class TestForThreeAttribute : TestBase
    {
        protected override string Title => "测试三大特性之二：继承、多态";

        public override void OnRunTest()
        {
            ITestInherit testObj = null;

            testObj = new TestInheritBase();
            testObj.Test1();
            testObj = new TestChild();
            testObj.Test1();
        }
    }

    public interface ITestInherit
    {
        void HandleX();

        void Test1();
        void Test2();
    }

    public class TestInheritBase : ITestInherit
    {
        public void HandleX()
        {
            try
            {
                OnHandleX();
            }
            catch (Exception x)
            {
                // 记录日志
                throw;
            }
        }

        public virtual void OnHandleX()
        {
            throw new NotImplementedException();
        }

        public virtual void HandleStep1()
        {
            throw new NotImplementedException();
        }

        public virtual void HandleStep2()
        {
            throw new NotImplementedException();
        }

        public virtual void HandleStep3()
        {
            throw new NotImplementedException();
        }

        public virtual void Test1()
        {
            Console.WriteLine("Test1：TestInheritBase...");
        }

        public virtual void Test2()
        {
            Console.WriteLine("Test2：TestInheritBase...");
        }
    }

    public class TestChild : TestInheritBase
    {
        public override void OnHandleX()
        {
            new HandleXImpl().Run();
        }

        public override void Test1()
        {
            Console.WriteLine("Test1：TestChild...");
        }
        public override void Test2()
        {
            Console.WriteLine("Test2：TestChild...");
        }
    }

    public class HandleXBase
    {
        public void Run()
        {
            Handle1();
            Handle2();
            Handle3();
        }

        public virtual void Handle1()
        {
            throw new NotImplementedException();
        }
        public virtual void Handle2()
        {
            throw new NotImplementedException();
        }
        public virtual void Handle3()
        {
            throw new NotImplementedException();
        }

    }

    public class HandleXImpl : HandleXBase
    {
        public override void Handle1()
        {

        }
        public override void Handle2()
        {

        }
        public override void Handle3()
        {

        }
    }

}
